/**
 * 0438
 *  
 * @Author : roryrywang
 * @DateTime : 2024/8/17 23:49
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    bool check(vector<int> &cnt, vector<int> &tmp) {
        for (int i = 0; i < cnt.size(); ++i) {
            if (cnt[i] != tmp[i])return false;
        }
        return true;
    }

    vector<int> findAnagrams(string s, string p) {
        vector<int> res;
        if (p.size() > s.size())return res;

        vector<int> cnt(26);
        vector<int> tmp(26);
        for (int i = 0; i < p.size(); ++i) {
            cnt[p[i] - 'a']++;
            tmp[s[i] - 'a']++;
        }
        for (int l = 0, r = p.size() - 1; r < s.size(); ++l, ++r) {
            if (l != 0) {
                tmp[s[l - 1] - 'a']--;
                tmp[s[r] - 'a']++;
            }
            if (check(cnt, tmp)) res.push_back(l);
        }
        return res;
    }
};

int main() {

    return 0;
}